require 'xcodeproj'


project_path = ARGV[0]
project_identifier = ARGV[1]
team_identifier = ARGV[2]
cer_name = ARGV[3]
profile_uuid = ARGV[4]
puts 'xcodeproj: ' + project_path
puts 'project_identifier: ' + project_identifier
puts 'team_identifier: ' + team_identifier
puts 'cer_name: ' + cer_name
puts 'profile_uuid: ' + profile_uuid
project = Xcodeproj::Project.open(project_path)

project.targets.each do |target|
  if target.name == 'Runner'
    target.build_configurations.each do |config|
      # puts config
      # config.each do |key, value|
      #   puts key
      # end
      # config.build_settings.each do |key, value|
      #   if key != 'LD_RUNPATH_SEARCH_PATHS'
      #     puts key + ':' + value
      #   end
      # end
      config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = project_identifier
      config.build_settings['DEVELOPMENT_TEAM'] = team_identifier
      config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = profile_uuid
      config.build_settings['CODE_SIGN_STYLE'] = 'Manual'
      config.build_settings['CODE_SIGN_IDENTITY'] = cer_name
      # config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = cer_name
    end
  end
end

project.save